/**
 * 
 */
package travibot.model.buildings;

import java.text.MessageFormat;

import travibot.meta.StructureType;
import travibot.model.Building;
import travibot.model.Cost;
import travibot.model.Level;
import travibot.model.Position;
import travibot.model.Structure;
import travibot.resource.ResourceHelper;

/**
 * @author Petr Macek
 * 
 */
public abstract class AbstractBuilding implements Building {

    private String buildLink;

    private String detailLink;

    private Level level;

    private String name;

    private Position position;

    private String upgradeLink;

    protected StructureType structureType;

    public AbstractBuilding(Position position) {

        super();
        this.position = position;
    }

    public String getBuildLink() {

        if (buildLink == null) {
            String mask = ResourceHelper.getKeyValue("links", "structure.build");
            buildLink = MessageFormat.format(mask, structureType.getGameId(), position.getId());
        }
        return buildLink;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getDetailLink()
     */
    public String getDetailLink() {

        return detailLink;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getLevel()
     */
    public Level getLevel() {

        return level;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getName()
     */
    public String getName() {

        return name;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getNextLevelCost()
     */
    public Cost getNextLevelCost() {

        // TODO Auto-generated method stub
        return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getPosition()
     */
    public Position getPosition() {

        return position;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getType()
     */
    public Type getType() {

        return Structure.Type.BUILDING;
    }

    /*
     * (non-Javadoc)
     * 
     * @see travibot.engine.Structure#getUpgradeLink()
     */
    public String getUpgradeLink(int villageId) {

        if (upgradeLink == null) {
            String mask = ResourceHelper.getKeyValue("links", "structure.upgrade");
            upgradeLink = MessageFormat.format(mask, position.getId(), villageId);
        }
        return upgradeLink;
    }

    public void setBuildLink(String buildLink) {

        this.buildLink = buildLink;
    }

    public void setDetailLink(String detailLink) {

        this.detailLink = detailLink;
    }

    public void setLevel(Level level) {

        this.level = level;
    }

    public void setMetaData(StructureType structureType) {

        this.structureType = structureType;
    }

    public void setName(String name) {

        this.name = name;
    }

    public void setUpgradeLink(String upgradeLink) {

        this.upgradeLink = upgradeLink;
    }

}
